package 二叉树题目.二叉搜索树与双向链表;

public class Solution {
    TreeNode prev = null;

    public TreeNode Convert(TreeNode pRootOfTree) {
       ConvertNode(pRootOfTree);
       TreeNode head = pRootOfTree;
       while (head !=null && head.left != null){
           head = head.left;
       }
       return head;
    }

    public void ConvertNode(TreeNode pCur) {
        if (pCur == null) {
            return;
        }
        ConvertNode(pCur.left);
        // 开始调整指向
        pCur.left = prev;
        if (prev != null) {
            prev.right = pCur;
        }
        prev = pCur;
        ConvertNode(pCur.right);
    }
}
